alter procedure sism_bonifica_popola_SISM_EVENTI_PROG_CONTATTO
AS
BEGIN 
SET NOCOUNT ON;
DECLARE @ID_EVENTI_LOG_ROW AS INT
DECLARE @FK_ID_CONTATTO AS INT

DECLARE my_Cursor CURSOR FAST_FORWARD FOR 
  select  IDENTITY_TABELLA as FK_COD_T_ATTI_SISM, a.COD_T_CONTATTI_SISM  as FK_ID_CONTATTO FROM SISM_EVENTI_MESSAGGI M, SISM_EVENTI_LOG L,  SISM_T_ATTI A
  where M.stato =0  and M.ID_EVENTI_LOG =L.ID 
  and M.MESSAGGO_ERRORE like '%ProgressivoPrestazioniContatto%'
  and a.COD_T_ATTI_SISM = l.IDENTITY_TABELLA;
  
  OPEN my_Cursor 
 FETCH NEXT FROM my_Cursor into @ID_EVENTI_LOG_ROW, @FK_ID_CONTATTO
 
 WHILE @@FETCH_STATUS = 0 
 BEGIN
     INSERT INTO [SISM_EVENTI_PROG_CONTATTO] ([FK_ID_CONTATTO] , [FK_COD_T_ATTI_SISM]) VALUES (@FK_ID_CONTATTO,@ID_EVENTI_LOG_ROW);
	  
	 FETCH NEXT FROM my_Cursor into @ID_EVENTI_LOG_ROW, @FK_ID_CONTATTO 
 END
end